// pages/product/list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTimeline:0,
    page:1,
    timelines: [],
    products:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    console.log('log');
    console.log(getApp().globalData.baseUrl);

    this.loadPage();
    this.loadTimeline();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  loadPage: function(){
    var self = this;
    var page = 1;
    if(this.products)
    {
      if(products.page<products.total_page)
      {
        page = products.page;
      }
      else
      {
        //stop load
        console.log("stop load");
        return ;
      }
    }

    const requestTask = wx.request({
      url: getApp().globalData.baseUrl + "/index.php?r=v1/product/index",
      success: function (res) {
        console.log(res);
        self.setData(
          { products: res.data.data }
        )
        console.log(self.data.products);
      }
    });
  },
  loadTimeline:function(){
    var self = this;
    const requestTask = wx.request({
      url: getApp().globalData.baseUrl + "/index.php?r=v1/timeline/index",
      success: function (res) {
        console.log(res);
        self.setData(
          { timelines: res.data.data }
        )
        console.log(self.data.timelines);
      }
    })
  },
  swichNav: function(e)
  {
    console.log(e);
    console.log(e.currentTarget.dataset.id);
    this.setData({ currentTimeline: e.currentTarget.dataset.id});
    this.loadPage();
  }
})